package com.kimoge.spring6.resources.resource;

import org.springframework.core.io.FileSystemResource;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author kimoge
 * @date 2025/8/30
 * @description 测试FileSystemResource类
 */
public class FileSystemResourceDemo {
    public static void main(String[] args) {
        String filePath = "d:\\properties2.txt";
        loadResource(filePath);
    }

    public static void loadResource(String filePath) {
        FileSystemResource fileSystemResource = new FileSystemResource(filePath);
        System.out.println(fileSystemResource.getFilename());
        System.out.println(fileSystemResource.getDescription());
        System.out.println(fileSystemResource.getPath());

        try {
            InputStream inputStream = fileSystemResource.getInputStream();
            byte[] bytes = new byte[inputStream.available()];
            inputStream.read(bytes);
            System.out.println(new String(bytes));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
